package me.algo.lst;

/**
 * @author guozheng
 * @date 2024/4/25
 */
public class L6 {
    public static void main(String[] args) {
        int i = Math.floorDiv(3, 5);

        System.out.println(i);
        int i1 = Math.floorMod(3, 5);
        System.out.println(i1);
    }

    /**
     * 725. 分隔链表
     * @param head
     * @param k
     * @return
     */
    public static ListNode[] splitListToParts(ListNode head, int k) {
        int len = 0;
        ListNode hc = head;
        while (hc != null) {
            len++;
            hc = hc.next;
        }
        if (len == 0) {
            return new ListNode[k];
        }
        int count = Math.floorDiv(len, k);
        int rem = Math.floorMod(len, k);
        ListNode[] rtn = new ListNode[k];
        ListNode cc = head;
        for (int i = 0; i < k; i++) {
            int time = count;
            if (rem > 0) {
                time += 1;
                rem--;
            }
            ListNode dummy = new ListNode();
            ListNode dc = dummy;
            while (time > 0 && cc != null) {
                dc.next = cc;
                dc = dc.next;
                cc = cc.next;
                time--;
            }
            dc.next = null;
            rtn[i] = dummy.next;
        }
        return rtn;
    }
}
